package cn.stu.cms.controller;


import cn.stu.cms.dto.CustomersDto;
import cn.stu.cms.dto.PageDto;
import cn.stu.cms.dto.SetTeamDto;
import cn.stu.cms.pojo.Customers;
import cn.stu.cms.service.CustomersService;
import cn.stu.cms.service.UsersService;
import cn.stu.cms.util.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * (Customers)表控制层
 *
 * @author gh
 * @since 2023-07-20 14:38:50
 */
@RestController
@RequestMapping("/customer")
@AllArgsConstructor
public class CustomersController {

    private final CustomersService customersService;

    private final UsersService usersService;



    /**
     * 查询全部数据
     *
     * @return 全部数据
     */
    @GetMapping("/page")
    public R<Page<Customers>> getPage(PageDto<Customers> pageDto, Customers customers) {

        return customersService.getPage(pageDto, customers);
    }

    @GetMapping("/list")
    public R<List<Customers>> getList() {

        return customersService.getList();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param customersId 主键
     * @return 单条数据
     */
    @GetMapping("/info")
    public R<Customers> getById(Integer customersId) {
        return customersService.customersSelectById(customersId);
    }

    /**
     * 新增数据
     *
     * @param dto 实体对象
     * @return 新增结果
     */
    @PostMapping("/add")
    public R<Boolean> insert(@RequestBody @Valid CustomersDto dto) {
        return customersService.add(dto);
    }

    /**
     * 修改数据
     *
     * @param dto 实体对象
     * @return 修改结果
     */
    @PutMapping("/update")
    public R<Boolean> update(@RequestBody @Valid CustomersDto dto) {
        return customersService.edit(dto);
    }

    /**
     * 删除数据
     *
     * @param id ID
     * @return 删除结果
     */
    @DeleteMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable Long id) {
        return customersService.delete(id);
    }

    @PostMapping("/setTeam")
    public R<Boolean> setTeam(@RequestBody @Valid SetTeamDto setTeamDto) {
        return customersService.setTeam(setTeamDto);
    }
}